var  vm = new Vue({
    el:'#systemNotice',
    data:{
        loading: true,
        user_id:'',
        user_name:'',
        city:'',
        web_token:'',
        orderList:[],
        shopList:[],
        noticeList:[],
        detailsList:[],
        page: 1,            //订单页码
        paginate:'',
        page_no:1,          //商家推广分页
        shopHtml:'',
        pageNo:1,           //通知分页
        noticeHtml:'',
        url:oss_url,
        nodata:''
    },
    methods:{
        // 订单状态
        order:function () {
            this.loading    = true;
            $("#orderStatus").show();
            $("#businessActive").hide();
            $("#notification").hide();
            $("#order_tran_details").hide();
            var url = '/userweb/My/orderSystem';
            var data = {
                id:     this.user_id,
                page:   this.page
            };
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    this.orderList = res.data.notice;
                    this.paginate  = res.data.paginate;
                    for (var i=0;i<this.orderList.length;i++){
                        for (var k=0;k<this.orderList[i]['product'].length;k++){
                            this.orderList[i]['product'][k]['image'] = this.url + this.orderList[i]['product'][k]['image'];
                        }
                    }
                }
                if (this.orderList.length == 0){
                    $('#noData').html(this.nodata);
                }else {
                    $('#noData').html("");
                }
               /* var _this = this;
                setTimeout(function () {
                    _this.loading = false;
                }, 300);*/
               this.loading = false;
            }, function (res) {

            });
        },
        // 查看交易详情
        details:function (id) {
            this.loading = true;
            var url = '/userweb/My/orderTransport';
            var data = {
                order_id:id
            };
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    this.detailsList = res.data.order.list;
                    this.detailsList.image = this.url+this.detailsList.image;
                }
                this.loading = false;
            }, function (res) {

            });
        },
        // 商家推广
        shop:function () {
            this.loading    = true;
            $("#orderStatus").hide();
            $("#businessActive").show();
            $("#notification").hide();
            $("#order_tran_details").hide();
            var url = '/userweb/My/shopSystem';
            var data = {
                id:     this.user_id,
                page_no:this.page_no
            };
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    this.shopList = res.data.shopNotice;
                    this.shopHtml = res.data.shopHtml;
                    if (this.shopHtml){
                        this.shopHtml   = this.shopHtml.replace(/jump/, "JumTwo");
                        this.shopHtml   = this.shopHtml.replace(/page_no/, "pageNo");
                    }
                    for (var i=0;i<this.shopList.length;i++){
                        this.shopList[i]['image'] = this.url+this.shopList[i]['image'];
                    }
                }
                if (this.shopList.length == 0){
                    $('#noData').html(this.nodata);
                }else {
                    $('#noData').html("");
                }
                /*var _this = this;
                setTimeout(function () {
                    _this.loading = false;
                }, 300);*/
                this.loading = false;
            }, function (res) {

            });

        },
        // 通知
        notice:function () {
            this.loading    = true;
            $("#orderStatus").hide();
            $("#businessActive").hide();
            $("#notification").show();
            $("#order_tran_details").hide();
            var url = '/userweb/My/noticeSystem';
            var data = {
                id:     this.user_id,
                pageNo: this.pageNo
            };
            this.$http.post(url, data, {
                emulateJSON: true
            }).then(function (res) {
                if (res.data.status == 200) {
                    this.noticeList = res.data.data;
                    this.noticeHtml = res.data.noticeHtml;
                }
                if (this.noticeHtml){
                    this.noticeHtml   = this.noticeHtml.replace(/jump/, "JumThree");
                    this.noticeHtml   = this.noticeHtml.replace(/page_no/, "PageNo");
                }
                for (var i=0;i<this.noticeList.length;i++){
                    this.noticeList[i]['image'] = this.url+this.noticeList[i]['image'];
                }
                if (this.noticeList.length == 0){
                    $('#noData').html(this.nodata);
                }else {
                    $('#noData').html("");
                }
                /*var _this = this;
                setTimeout(function () {
                    _this.loading = false;
                }, 300);*/
                this.loading = false;
            }, function (res) {

            });

        },
        //跳转商户页面
        jumpSupplier:function (list) {
            location.href = '/userweb/index/shopList.html?supplierId='+list.supplier_id;
        }
    },
    mounted: function () {
        this.nodata += '<div class="my_no-data">';
        this.nodata += '<div class="no_data_tip">';
        this.nodata += '<img src="/image/userweb/slicesImg/no-data.png" alt="">';
        this.nodata += '<div class="no-data-text">';
        this.nodata += '<div class="title_zh">暂无数据</div>';
        this.nodata += '<div class="title_en">No data</div>';
        this.nodata += '</div>';
        this.nodata += '</div>';
        this.nodata += '</div>';
        this.user_id        = localStorage.getItem('user_id');
        this.user_name      = localStorage.getItem('user_name');
        this.city           = localStorage.getItem('city');
        this.web_token      = localStorage.getItem('web_token');
        if (!this.user_id ){
            location.href = "/userweb/index/login.html";
        }
        this.order();
    }
});
function AjaxPage(page) {
    vm.page = page;
    vm.order();
}
function jump(){
    var page = $("#page_no").val();
    vm.page = page;
    vm.order();
}

function ajaxPage(page) {
    vm.page_no = page;
    vm.shop();
}
function JumTwo(){
    var page = $("#pageNo").val();
    vm.page_no = page;
    vm.shop();
}

function ajax_page(page) {
    vm.pageNo = page;
    vm.notice();
}
function JumThree(){
    var page = $("#PageNo").val();
    vm.pageNo = page;
    vm.notice();
}